package _21_多线程juc.demo03;


/**
 * 用户线程 和 守护线程的 区别
 *      核心区别
 *
 * @author liuhuan
 */
public class DaemonTest {

    public static void main(String[] args) {
        System.out.println("==== main start ====");

        Thread threadOfDaemon = new Thread("守护线程") {
            @Override
            public void run() {
                int i = 0;
                while (i < 10) {
                    i++;
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + " ： " + i);
                }
            }
        };

        Thread threadOfUser = new Thread("用户线程") {
            @Override
            public void run() {
                int i = 0;
                while (i < 3) {
                    i++;
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + " ： " + i);
                }
            }
        };

        threadOfDaemon.setDaemon(false);
        threadOfUser.setDaemon(false);

        threadOfDaemon.start();
        threadOfUser.start();
    }

}
